using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEditor;
using ExcelDataReader;
using System.Data;
using System;
using System.Linq;

public class ExcelInputer : MonoBehaviour
{
    public string[] filePaths;
    public List<ExcelFile> files;
    public void Awake()
    {
        files = new List<ExcelFile>();
        for (int i = 0; i < filePaths.Length; i++)
        {
            files.Add(new ExcelFile(filePaths[i]));
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        //foreach (ExcelFile file in files)
        //{
        //    Debug.Log(file);
        //}
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
public class ExcelFile
{
    public string[,] values;
    public int columns;
    public int rows;
    public ExcelFile(string filePath)
    {
        var stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
        IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
        DataSet result = excelReader.AsDataSet();
        stream.Close();
        columns = result.Tables[0].Columns.Count;
        rows = result.Tables[0].Rows.Count;
        values=new string[rows, columns];
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < columns; j++)
            {
                values[i,j] = result.Tables[0].Rows[i][j].ToString();
            }
        }
        
    }
    public override string ToString()
    {
        string res = "";
        for(int i = 0; i < this.rows; i++)
        {
            for(int j=0; j < this.columns; j++)
            {
                res += this.values[i, j] + ",";

            }
            res += "\n";
        }
        return res;
    }
}
